import 'package:flutter/material.dart';
import 'package:flutter_basic/pages/01%E6%8B%86%E5%88%86%E5%87%BA%E6%9D%A5%E7%9A%84counter%E7%BB%84%E4%BB%B6.dart';
import 'package:flutter_basic/pages/02%E7%BB%84%E4%BB%B6%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F.dart';
import 'package:flutter_basic/pages/03Container%E7%BB%84%E4%BB%B6.dart';
import 'package:flutter_basic/pages/04%E6%96%87%E6%9C%AC%E7%BB%84%E4%BB%B6.dart';
import 'package:flutter_basic/pages/05image%E7%BB%84%E4%BB%B6.dart';
import 'package:flutter_basic/pages/06%E5%B8%83%E5%B1%80%E7%BB%84%E4%BB%B6Column.dart';
import 'package:flutter_basic/pages/07%E5%B8%83%E5%B1%80%E7%BB%84%E4%BB%B6Row.dart';
import 'package:flutter_basic/pages/08%E5%B8%83%E5%B1%80%E7%BB%84%E4%BB%B6Expanded.dart';
import 'package:flutter_basic/pages/09%20Stack%E7%BB%84%E4%BB%B6.dart';
import 'package:flutter_basic/pages/10-1%20%E6%BB%9A%E5%8A%A8%E7%BB%84%E4%BB%B6ListView-%E9%BB%98%E8%AE%A4%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0.dart';
import 'package:flutter_basic/pages/10-2%20%E6%BB%9A%E5%8A%A8%E7%BB%84%E4%BB%B6ListView-builder%E5%87%BD%E6%95%B0.dart';
import 'package:flutter_basic/pages/10-3%20%E6%BB%9A%E5%8A%A8%E7%BB%84%E4%BB%B6ListView-%E5%B8%A6%E5%88%86%E5%89%B2%E7%BA%BF.dart';
import 'package:flutter_basic/pages/11-1%20%E6%BB%9A%E5%8A%A8%E7%BB%84%E4%BB%B6GridView-%E9%BB%98%E8%AE%A4%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0.dart';
import 'package:flutter_basic/pages/11-2%20%E6%BB%9A%E5%8A%A8%E7%BB%84%E4%BB%B6GridView-builder%20%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0.dart';
import 'package:flutter_basic/pages/11-3%20%E6%BB%9A%E5%8A%A8%E7%BB%84%E4%BB%B6GridView-extent%20%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0.dart';
import 'package:flutter_basic/pages/12%20%E8%B7%AF%E7%94%B1.dart';
import 'package:flutter_basic/pages/detail_page.dart';
import 'package:flutter_basic/models/DemoModel.dart';

void main() {
  runApp(MyDemo());
}

class MyDemo extends StatelessWidget {
  const MyDemo({super.key});

  @override
  Widget build(BuildContext context) {
    // 根组件
    return MaterialApp(
      title: '学习示例',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.black),
      ),
      home: MyDemoHome(),
      // 路由配置
      routes: {
        // 默认显示MyDemoHomePage页面
        // '/': (context) => MyDemoHomePage(),
        '/homePage01': (context) => HomePage01(),
        '/homePage02': (context) => HomePage02(),
        '/homePage03': (context) => HomePage03(),
        '/homePage04': (context) => HomePage04(),
        '/homePage05': (context) => HomePage05(),
        '/homePage06': (context) => HomePage06(),
        '/homePage07': (context) => HomePage07(),
        '/homePage08': (context) => HomePage08(),
        '/homePage09': (context) => HomePage09(),
        '/homePage10_1': (context) => HomePage10_1(),
        '/homePage10_2': (context) => HomePage10_2(),
        '/homePage10_3': (context) => HomePage10_3(),
        '/homePage11_1': (context) => HomePage11_1(),
        '/homePage11_2': (context) => HomePage11_2(),
        '/homePage11_3': (context) => HomePage11_3(),
        '/homePage12': (context) => HomePage12(),
        '/detail': (context) => DetailPage(),
      },
    );
  }
}

class MyDemoHome extends StatelessWidget {
  MyDemoHome({super.key});

  final List<DemoModel> myDemos = [
    DemoModel('01拆分出来的counter组件', '/homePage01'),
    DemoModel('02组件生命周期', '/homePage02'),
    DemoModel('03Container组件', '/homePage03'),
    DemoModel('04文本组件', '/homePage04'),
    DemoModel('05image组件', '/homePage05'),
    DemoModel('06布局组件Column', '/homePage06'),
    DemoModel('07布局组件Row', '/homePage07'),
    DemoModel('08布局组件Expanded', '/homePage08'),
    DemoModel('09 Stack组件', '/homePage09'),
    DemoModel('10-1 滚动组件ListView 默认构造函数', '/homePage10_1'),
    DemoModel('10-2 滚动组件ListView builder函数', '/homePage10_2'),
    DemoModel('10-3 滚动组件ListView 带分割线', '/homePage10_3'),
    DemoModel('11-1 滚动组件GridView 默认构造函数', '/homePage11_1'),
    DemoModel('11-2 滚动组件GridView.builder 构造函数', '/homePage11_2'),
    DemoModel('11-3 滚动组件GridView.extent 构造函数', '/homePage11_3'),
    DemoModel('12 路由', '/homePage12'),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Center(
          child: Text(
            '学习示例列表',
            style: TextStyle(
              color: Colors.white,
              fontWeight: FontWeight.bold,
              fontStyle: FontStyle.italic,
              fontSize: 25,
            ),
          ),
        ),
        backgroundColor: Colors.orange,
      ),
      body: ListView.builder(
        itemBuilder: (context, index) {
          DemoModel demo = myDemos[index];
          return TextButton(
            style: ButtonStyle(alignment: Alignment.centerLeft),
            onPressed: () {
              Navigator.pushNamed(context, demo.demoRouter);
            },
            child: Text(demo.demoName),
          );
        },
        itemCount: myDemos.length,
      ),
    );
  }
}
